package managers;

import java.util.ArrayList;

import finobjects.Account;

public class AccountManager {

	private static ArrayList<Account> accounts;
	private static boolean initialized = false; 
	
	
	public static void addAccount (Account a) {
		if(!AccountManager.initAndCheckIfContains(a)) {
			AccountManager.accounts.add(a);
		}
		else {
			System.out.println("WARN: Account already in accountslist!");
		}
	}
	
	public static ArrayList<Account> getAccounts() {
		return AccountManager.accounts;
	}
	
	public static void removeAccount (Account a) {
		if(AccountManager.initAndCheckIfContains(a)) {
			AccountManager.accounts.remove(a);
		}
		else {
			System.out.println("WARN: Account not in accountslist!");
		}
	}
	
	public static Account getAccountByNumber(int number){
		initAccountManager();
		for(Account a : AccountManager.accounts){
			if(a.getAccountNumber() == number){
				return a;
			}
		}
		return null;
	}
	
	private static void initAccountManager() {
		if(!AccountManager.initialized) {
			AccountManager.accounts = new ArrayList<Account>();
			AccountManager.initialized= true; 
		}
	}
	
	private static boolean initAndCheckIfContains(Account a) {
		boolean out = false;
		initAccountManager();
			
		if(AccountManager.accounts.contains(a)) {
			out = true;
		}
		
		return out;
	}
}
